#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>


char* add_env = "hello=1314";

int main(int argc, char* argv[])
{
    pid_t pid = fork();
    extern char** environ;
    putenv(add_env);
    if(pid == 0)
    {
        printf("我是一个进程：%d\n", getpid());
        //char* const myargv[] = { (char*)"ls", (char*)"-l", NULL };
        //execl("/usr/bin/ls", "ls", "-l", NULL);
        //execv("/usr/bin/ls", myargv);
        //char** myargv = &argv[1];
        //execv(myargv[0], myargv);
        //execlp("ls", "ls", "-l", NULL);
        //execvp("ls", myargv);
        //execl("./mycmd", "mycmd", NULL);
        char* const myagrv[] = { (char*)"mycmd", NULL };
        //char* const myenv[] = { (char*)"hello=1314", NULL };
        execvpe("./mycmd", myagrv, environ);
        printf("程序替换失败\n");
        exit(1);
    }
    pid_t ret_pid = waitpid(pid, NULL, 0);
    if(ret_pid > 0)
    {
        printf("wait %d success\n", pid);
    }

    return 0;
}
